ifeq ($(OS),Windows_NT)
export ICE_TOOLS_BIN=D:/msys64/mingw64/bin/
export ICESPROG = $(ICE_TOOLS_BIN)icesprog 
else
export ICE_TOOLS_BIN=
export ICESPROG = icesprog 
endif 


rtl_src  ?= ../rtl/top.v 
pcf_file ?= io.pcf

ICELINK_DIR = $(shell df | grep iCELink | awk '{print $$6}')
${warning iCELink path: $(ICELINK_DIR)}
ICELINK_DIR = H:/




synth:rtl 
	mkdir -p build 
	cp *.pcf build 
	cd build && $(ICE_TOOLS_BIN)yosys -p "synth_ice40 -json synth.json -blif synth.blif "  $(rtl_src)
ifeq ($(OS),Windows_NT)
	cd build && $(ICE_TOOLS_BIN)nextpnr-ice40 --lp1k --package cm36 --json synth.json --pcf $(pcf_file) --asc synth.asc --freq 24 
else 
	cd build && arachne-pnr -d 1k -P cm36 -p $(pcf_file)  synth.blif -o synth.asc
endif
	cd build && $(ICE_TOOLS_BIN)icepack synth.asc synth.bin 

timing:
	cd build && $(ICE_TOOLS_BIN)icetime -tmd lp1k *.asc   

prog_flash:
	$(ICESPROG) build/synth.bin


# 设置时钟频率
8M:
	$(ICESPROG) -c 1

12M:
	$(ICESPROG) -c 2

36M:
	$(ICESPROG) -c 3

72M:
	$(ICESPROG) -c 4
